/**
 * 历史月结记录管理初始化
 */
var Monthbalance = {
    id: "MonthbalanceTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Monthbalance.initColumn = function () {
    return [
        {type: 'checkbox', fixed: 'left'},
        {title: '结算批次', field: 'id', visible: true, align: 'center', valign: 'middle'},
        {title: '结算类型', field: 'balance_type', visible: true, align: 'center', valign: 'middle'},
        // {title: '关联单号', field: 'balance_num', visible: true, align: 'center', valign: 'middle',
        //     templet: function (d) {
        //         return d.balance_type+"单号"+d.balance_num ;
        //     }
        // },
        {title: '结算账单数', field: 'batch_count', visible: true, align: 'center', valign: 'middle'},
        {title: '结算对象', field: 'traner', visible: true, align: 'center', valign: 'middle'},
        {title: '应收金额', field: 'money_should', visible: true, align: 'center', valign: 'middle'},
        {title: '实收金额', field: 'money_actual', visible: true, align: 'center', valign: 'middle'},
        {title: '账单日期', field: 'createtime', visible: true, align: 'center', valign: 'middle'},
        {title: '制单员', field: 'name', visible: true, align: 'center', valign: 'middle'},
        {title: '备注', field: 'remark', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
Monthbalance.check = function () {
    var selected = mTable.checkStatus(Monthbalance.id);
    if (selected.data.length == 0 ) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        Monthbalance.seItem = selected.data[0];
        return true;
    }
};

/**
 * 打印
 */
Monthbalance.openAddMonthbalance = function () {
    var index = layer.open({
        type: 2,
        title: '打印账单',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/monthbalance/monthbalance_add'
    });
    layer.full(index)
    this.layerIndex = index;
};


/**
 * 账单明细
 */
Monthbalance.openMonthbalanceDetail = function () {
    if (this.check()) {

        var index = layer.open({
            type: 2,
            title: '账单明细',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/monthbalance/monthbalance_update/' + Monthbalance.seItem.id
        });
        layer.full(index)
        this.layerIndex = index;
     }
};

/**
 * 删除历史月结记录
 */
Monthbalance.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/monthbalance/delete", function (data) {
            Feng.success("删除成功!");
            Monthbalance.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("monthbalanceId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询历史月结记录列表
 */
Monthbalance.search = function () {
    var queryData = {};
    queryData['name'] = $("#condition").val();
    queryData['beginTime'] = $("#beginTime").val();
    queryData['endTime'] = $("#endTime").val();
    aTable.refresh(queryData);
};

$(function () {
    var defaultColunms = Monthbalance.initColumn();
    aTable = new LYTable(Monthbalance.id, "/monthbalance/list", defaultColunms);
    layui.use('table', function () {
        mTable = layui.table;
        Monthbalance.table = aTable.init(mTable);
    })


    $('#status').selectpicker({
        style: 'btn btn-select',
        noneSelectedText:"结算状态"
    });
});

$(document).keyup(function(event) {
    if (event.keyCode == 13) {
        Monthbalance.search();
    }
});

